//
//  UILabel+AXLabel.m
//  AnXin100
//
//  Created by 王合润 on 10/18/18.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "UILabel+AXLabel.h"

@implementation UILabel (AXLabel)



- (void)alignTop {
    CGSize fontSize = [self.text sizeWithFont:self.font];
    double finalHeight = fontSize.height * self.numberOfLines;
    double finalWidth = self.frame.size.width; //expected width of label
    CGSize theStringSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.lineBreakMode];
    int newLinesToPad = (finalHeight - theStringSize.height) / fontSize.height; for(int i=0; i<= newLinesToPad; i++) { self.text = [self.text stringByAppendingString:@" \n"];
    }
}

- (void)alignBottom {
    CGSize fontSize = [self.text sizeWithFont:self.font]; double finalHeight = fontSize.height * self.numberOfLines;
    double finalWidth = self.frame.size.width; //expected width of label
    CGSize theStringSize = [self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.lineBreakMode];
    int newLinesToPad = (finalHeight - theStringSize.height) / fontSize.height; for(int i=0; i< newLinesToPad; i++) { self.text = [NSString stringWithFormat:@" \n%@",self.text];
    }
}

+ (UILabel *)getCustomLabel:(UIColor *)color font:(UIFont *)font rect:(CGRect)rect{
    UILabel *label = [[UILabel alloc] init];
    label.textColor = color;
    label.font = font;
    if (rect.size.width == 0  && rect.size.height == 0) {
        
    } else {
        label.frame = rect;
    }
    return label;
}
@end
